package com.zcxk.exception;

import com.zcxk.enums.ErrorCodeEnum;

public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = -8559448572367908328L;
    private ErrorCodeEnum errorCode;
    private int code;
    public ServiceException(ErrorCodeEnum errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.errorCode = errorCode;
    }

    public ErrorCodeEnum getErrorCodeEnum() {
        return errorCode;
    }

    public int getCode() {
        return code;
    }

    public ServiceException(int errorCode, String message) {
        super(message);
        this.code = errorCode;
    }

    public ServiceException(ErrorCodeEnum errorCode, Throwable clauses) {
        super(errorCode.getMessage(), clauses);
    }

    @Override
    public String getMessage() {
        if (errorCode != null) {
            return errorCode.getMessage();
        }
        return super.getMessage();
    }
}
